<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">期初库存导入</h3></div>
            <div class="panel-body">
                <form id="import-form" method="post" enctype="multipart/form-data" class="form-horizontal">
                    <div class="form-group">
                        <label  class="col-md-2">导入模板：</label>
                        <div class="col-md-6 col-sm-10" style="cursor:pointer; ">
                            <a class="icon-arrow-down download">下载导入模板(支持xls,xlsx格式文件)</a>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-md-2">选择文件:</label>
                        <div class="col-md-3 col-sm-10">
                            <input class="btn" type="file" name="file" />
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-6">
                            <input class="btn btn-success btn-import" type="button" value="导入" />
                        </div>
                    </div>
                </form>
                <div class="alert alert-danger message" role="alert" style="display:none">
                </div>                    
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //下载导入模板
    $(".download").click(function () {
        var fileName = '期初库存导入模板';
        var list = new Array(['sku'], ['储位'], ['数量'], ['出口退税/非出口退税'], ['备注']);
        var list1 = new Array(['A401'], ['MH-001'], ['100'], ['出口退税'], ['备注一']);
        window.location.href ="Warehouse/StockIn/download?"+"&fileName="+fileName+"&list="+list+"&list1="+list1;
    });

    //导入
    $('.btn-import').click(function() {
        var file = $('input[name="file"]').val();
        if (file == '') {
            layer.msg('请选择导入文件', {icon: 5});
            return false;
        }

        $(this).attr('disabled', 'disabled').val('导入中...');
        $.ajax({
            url: 'Warehouse/StockIn/warehouse_import',
            type: 'POST',
            cache: false,
            data: new FormData($('#import-form')[0]),
            processData: false,
            contentType: false,
            success: function (result) {
                $('.message').html(result.info).show();
                $('.btn-import').removeAttr('disabled').val('导入');
                if (result.status) {
                    $('.message').removeClass('alert-danger').addClass('alert-success');
                } else {
                    $('.message').removeClass('alert-success').addClass('alert-danger');
                }
            }
        });
    });
</script>
